<?php

namespace App\Console\Commands;

use App\Http\Controllers\Admin\Ca\ComeWayController;
use App\Pool\Common;
use App\Utils\Encryption;
use App\Utils\Format;
use App\Utils\MessageEngine;
use App\Utils\Output;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

class TestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:test';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        dd(null==null);
        preg_match_all('/\$\{(.*?)\}/i', '${username}您好，${doctorname}医生邀请您填写”${questionaire}“。微信打开”C麦健康“公众号，点击调查问卷链接进行填写。您的答案有助于我们更全面地了解您的现状。', $matches);
        dd($matches);
        return ;
        $matches = [];
        preg_match_all('/^http(s)?:\/\/v3.antpool.com\/observer\?accessKey=(.*?)&coinType=(.*?)&observerUserId=(.*?)$/i', "https://v3.antpool.com/observer?accessKey=t8TyZmuWTTQpC7HZYE1s&coinType=ETH&observerUserId=llllllx", $matches);
        if (count($matches[2])) {
            $this->isObserver = true;
            $address = $matches[2][0];
        }
        dd($matches);
//        $api = new \App\Pool\SubAccount();
//        $apiResult = $api->getUserAddressMapping([
//            'coin' => 'eth',
//            'address'=>'0xef34329d956ea0b8a9161ff7abc2d54f0425ea53'
//        ]);
//        dd($apiResult);
//        mail('1364834365@qq.com', 'My Subject', 'The test mail');
//        dd($this->get('https://www.f2pool.com/eth/0xc9CbdECF32d30eEfC3e124Ef9c81e18529f69C2A', [
//            'draw' => 1,
//            'action' => 'anonymous_get_pagination_workers'
//        ]));
        $html=file_get_contents(base_path('doc/block.html'));
        preg_match_all("/ href='\/block\/(\d+)'/i", $html, $nums);
        preg_match_all("/(\d{4}-\d{1,2}-\d{1,2} \d{1,2}:\d{1,2}:\d{1,2})<\/span><\/td>/i", $html, $nums);
        dd($nums);
    }

    protected function get($url, $data = [])
    {
        $requestId = uniqid('', true);
        $httpClient = new \GuzzleHttp\Client(['timeout' => 10, 'verify' => false]);
        $response = $httpClient->get($url . '?' . http_build_query($data), [
            'headers' => [
                'x-requested-with' => 'XMLHttpRequest'
            ]
        ]);
        error_log(date('Y-m-d H:i:s') . "[$requestId]$url\r\n" . '?' . http_build_query($data) . "\r\n", 3, storage_path('logs') . date('/ymd') . '.log');
        $responseStr = $response->getBody()->getContents();
        error_log(date('Y-m-d H:i:s') . "[$requestId]" . $responseStr . "\r\n\r\n", 3, storage_path('logs') . date('/ymd') . '.log');
        $dd = json_decode($responseStr, true);
        return $dd;
    }
}
